<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/static/include/topLess.jsp" %>
<script type="text/javascript">
	document.title = "修改密码";
</script>

<div style="position:absolute; margin-top:30px; width:100%">
<c:if test="${isInitPass eq 'true'}">
	<div style="margin:0 auto; width:80%; color:red">注：请尽快修改您的登陆密码，登陆密码必须为字母+数字组合</div>
</c:if>
<table id="listTable" style="margin:0 auto; width:80%;">
	<thead>
		<tr style="display:none"><td></td></tr>
	</thead>
	<tbody>
		<tr>
			<td align="right">用户名：</td>
			<td>${sessionScope.user.userLoginname}</td>
		</tr>
		<tr>
			<td align="right">旧密码：</td>
			<td><input id="oldPwd" class="tab_textbut" type="password"><font color="red">*</font></td>
		</tr>
		<tr>
			<td align="right">新密码：</td>
			<td><input id="newPwd" class="tab_textbut" type="password"><font color="red">*</font></td>
		</tr>
		<tr>
			<td align="right">重复新密码：</td>
			<td><input id="confirmPwd" class="tab_textbut" type="password"><font color="red">*</font></td>
		</tr>
	</tbody>
</table>
	<div style="text-align:center; margin-top:10px">
		<a class="tab_but" href="#" onclick="modPwd()">保存</a>
	</div>
</div>
<script type="text/javascript">

	var reg = new RegExp(/^(?=.*?[a-z)(?=.*>[A-Z])(?=.*?\d)[a-zA_Z\d]{8,18}$/);

	function modPwd(){
		if ($("#oldPwd").val() == ""){
			alert_msg("请输入旧密码");
			return;
		}
		
		if ($("#newPwd").val() == ""){
			alert_msg("请输入新密码");
			return;
		}
		
		if ($("#confirmPwd").val() == ""){
			alert_msg("请重复输入新密码");
			return;
		}
		
		if (!reg.test($("#newPwd").val())){
			alert_msg("密码必须包含字母和数字的8到18位字符");
			return;
		}
		
		if ($("#newPwd").val() != $("#confirmPwd").val()){
			alert_msg("两次输入的密码不一致！");
			return;
		}
		
		var url = "${baseURL}/user/modPassword";
		var datas = "loginName=${sessionScope.user.userLoginname}&oldPwd=" + $("#oldPwd").val() + "&newPwd=" + $("#newPwd").val();
		$.ajax({
			url:url,
			dataType:'json',
			type:'post',
			data: datas,
			success : function(msg){
				if (msg == "success"){
					alert_msg("操作成功！", 1, close_self);	
				}else{
					alert_msg("操作失败！");
				}
			}			
		});
		

			
		
	}
	
	function alert_msg(message, icon, fn){		
		$.layer({
			title:'提示',
			offset: ['20px',''],
			dialog:{type:icon, msg:message, yes:fn}
		});
	}
	
	function close_self(){
		var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
	}
</script>

<%@ include file="/static/include/bottom.jsp" %>